package com.wu.controller;

import com.wu.response.CommonReturnType;
import com.wu.service.UserFriendsService;
import com.wu.service.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author: 吴磊
 * @program: blog
 * @create: 2021-04-25 20:15
 */
@RestController
@Api(tags = "好友管理")
public class UserFriendController {

    @Autowired
    private UsersService usersService;

    @Autowired
    private UserFriendsService userFriendsService;


    /**
     * 返回指定用户关注的博主
     *
     * @return
     */
    @ApiOperation(value = "获取用户关注的博主")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户Id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, dataTypeClass = Integer.class)
    })
    @RequestMapping(value = "/getFriendInfo", method = RequestMethod.POST)
    public CommonReturnType getFriendInfo(@RequestParam("userId") String userId,
                                          @RequestParam("curPage") Integer curPage) {
        Map<String, Object> map = usersService.getFriendsByFriendIdList(userId, curPage);
        return CommonReturnType.create(map);
    }

    /**
     * 获取用户的粉丝
     *
     * @param userId
     * @param curPage
     * @return
     */
    @ApiOperation(value = "获取用户的粉丝")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户Id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, dataTypeClass = Integer.class)
    })
    @RequestMapping(value = "/getUserFans", method = RequestMethod.POST)
    public CommonReturnType getUserFans(@RequestParam("userId") String userId,
                                        @RequestParam("curPage") Integer curPage) {
        Map<String, Object> fans = usersService.getUserFansByUserId(userId, curPage);
        return CommonReturnType.create(fans);
    }

    /**
     * 根据好友Id删除好友
     *
     * @param friendId
     * @return
     */
    @ApiOperation(value = "根据好友Id删除好友")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "friendId", value = "好友Id", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/deleteFriend", method = RequestMethod.POST)
    public CommonReturnType tokenDeleteFriend(@RequestParam("friendId") String friendId) {
        userFriendsService.deleteById(friendId);
        return CommonReturnType.create(null);
    }

    /**
     * 添加好友（关注博主）
     *
     * @param friendId
     * @return
     */
    @ApiOperation(value = "添加好友（关注博主）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "friendId", value = "博主Id", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/addFriend", method = RequestMethod.POST)
    public CommonReturnType tokenAddFriend(@RequestParam("friendId") String friendId) {
        userFriendsService.addFriend(friendId);
        return CommonReturnType.create(null);
    }

}
